//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS IoTJobsDataPlane service.
///
/// IoT Jobs is a service that allows you to define a set of jobs — remote operations that are sent to and executed on one or more devices connected to Amazon Web Services IoT Core. For example, you can define a job that instructs a set of devices to download and install application or firmware updates, reboot, rotate certificates, or perform remote troubleshooting operations. Find the endpoint address for actions in the IoT jobs data plane by running this CLI command:  aws iot describe-endpoint --endpoint-type iot:Jobs  The service name used by Amazon Web Services Signature Version 4 to sign requests is: iot-jobs-data. To create a job, you make a job document which is a description of the remote operations to be performed, and you specify a list of targets that should perform the operations. The targets can be individual things, thing groups or both. IoT Jobs sends a message to inform the targets that a job is available. The target starts the execution of the job by downloading the job document, performing the operations it specifies, and reporting its progress to Amazon Web Services IoT Core. The Jobs service provides commands to track the progress of a job on a specific target and for all the targets of the job
public struct IoTJobsDataPlane: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the IoTJobsDataPlane client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "IoTJobsDataPlane",
            serviceIdentifier: "data.jobs.iot",
            signingName: "iot-jobs-data",
            serviceProtocol: .restjson,
            apiVersion: "2017-09-29",
            endpoint: endpoint,
            variantEndpoints: Self.variantEndpoints,
            errorType: IoTJobsDataPlaneErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }




    /// FIPS and dualstack endpoints
    static var variantEndpoints: [EndpointVariantType: AWSServiceConfig.EndpointVariant] {[
        [.fips]: .init(endpoints: [
            "ca-central-1": "data.jobs.iot-fips.ca-central-1.amazonaws.com",
            "us-east-1": "data.jobs.iot-fips.us-east-1.amazonaws.com",
            "us-east-2": "data.jobs.iot-fips.us-east-2.amazonaws.com",
            "us-gov-east-1": "data.jobs.iot-fips.us-gov-east-1.amazonaws.com",
            "us-gov-west-1": "data.jobs.iot-fips.us-gov-west-1.amazonaws.com",
            "us-west-1": "data.jobs.iot-fips.us-west-1.amazonaws.com",
            "us-west-2": "data.jobs.iot-fips.us-west-2.amazonaws.com"
        ])
    ]}

    // MARK: API Calls

    /// Gets details of a job execution. Requires permission to access the DescribeJobExecution action.
    @Sendable
    @inlinable
    public func describeJobExecution(_ input: DescribeJobExecutionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> DescribeJobExecutionResponse {
        try await self.client.execute(
            operation: "DescribeJobExecution", 
            path: "/things/{thingName}/jobs/{jobId}", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Gets details of a job execution. Requires permission to access the DescribeJobExecution action.
    ///
    /// Parameters:
    ///   - executionNumber: Optional. A number that identifies a particular job execution on a particular device. If not specified, the latest job execution is returned.
    ///   - includeJobDocument: Optional. Unless set to false, the response contains the job document. The default is true.
    ///   - jobId: The unique identifier assigned to this job when it was created.
    ///   - thingName: The thing name associated with the device the job execution is running on.
    ///   - logger: Logger use during operation
    @inlinable
    public func describeJobExecution(
        executionNumber: Int64? = nil,
        includeJobDocument: Bool? = nil,
        jobId: String,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> DescribeJobExecutionResponse {
        let input = DescribeJobExecutionRequest(
            executionNumber: executionNumber, 
            includeJobDocument: includeJobDocument, 
            jobId: jobId, 
            thingName: thingName
        )
        return try await self.describeJobExecution(input, logger: logger)
    }

    /// Gets the list of all jobs for a thing that are not in a terminal status. Requires permission to access the GetPendingJobExecutions action.
    @Sendable
    @inlinable
    public func getPendingJobExecutions(_ input: GetPendingJobExecutionsRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetPendingJobExecutionsResponse {
        try await self.client.execute(
            operation: "GetPendingJobExecutions", 
            path: "/things/{thingName}/jobs", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Gets the list of all jobs for a thing that are not in a terminal status. Requires permission to access the GetPendingJobExecutions action.
    ///
    /// Parameters:
    ///   - thingName: The name of the thing that is executing the job.
    ///   - logger: Logger use during operation
    @inlinable
    public func getPendingJobExecutions(
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetPendingJobExecutionsResponse {
        let input = GetPendingJobExecutionsRequest(
            thingName: thingName
        )
        return try await self.getPendingJobExecutions(input, logger: logger)
    }

    /// Using the command created with the CreateCommand API, start a command execution on a specific device.
    @Sendable
    @inlinable
    public func startCommandExecution(_ input: StartCommandExecutionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> StartCommandExecutionResponse {
        try await self.client.execute(
            operation: "StartCommandExecution", 
            path: "/command-executions", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Using the command created with the CreateCommand API, start a command execution on a specific device.
    ///
    /// Parameters:
    ///   - clientToken: The client token is used to implement idempotency. It ensures that the request completes no more than one time. If you retry a request with the same token and the same parameters, the request will complete successfully. However, if you retry the request using the same token but different parameters, an HTTP 409 conflict occurs. If you omit this value, Amazon Web Services SDKs will automatically generate a unique client request.
    ///   - commandArn: The Amazon Resource Number (ARN) of the command. For example, arn:aws:iot:::command/
    ///   - executionTimeoutSeconds: Specifies the amount of time in second the device has to finish the command execution. A timer is started as soon as the command execution is created. If the command execution status is not set to another terminal state before the timer expires, it will automatically update to TIMED_OUT.
    ///   - parameters: A list of parameters that are required by the StartCommandExecution API when performing the command on a device.
    ///   - targetArn: The Amazon Resource Number (ARN) of the device where the command execution is occurring.
    ///   - logger: Logger use during operation
    @inlinable
    public func startCommandExecution(
        clientToken: String? = StartCommandExecutionRequest.idempotencyToken(),
        commandArn: String,
        executionTimeoutSeconds: Int64? = nil,
        parameters: [String: CommandParameterValue]? = nil,
        targetArn: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> StartCommandExecutionResponse {
        let input = StartCommandExecutionRequest(
            clientToken: clientToken, 
            commandArn: commandArn, 
            executionTimeoutSeconds: executionTimeoutSeconds, 
            parameters: parameters, 
            targetArn: targetArn
        )
        return try await self.startCommandExecution(input, logger: logger)
    }

    /// Gets and starts the next pending (status IN_PROGRESS or QUEUED) job execution for a thing. Requires permission to access the StartNextPendingJobExecution action.
    @Sendable
    @inlinable
    public func startNextPendingJobExecution(_ input: StartNextPendingJobExecutionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> StartNextPendingJobExecutionResponse {
        try await self.client.execute(
            operation: "StartNextPendingJobExecution", 
            path: "/things/{thingName}/jobs/$next", 
            httpMethod: .PUT, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Gets and starts the next pending (status IN_PROGRESS or QUEUED) job execution for a thing. Requires permission to access the StartNextPendingJobExecution action.
    ///
    /// Parameters:
    ///   - statusDetails: A collection of name/value pairs that describe the status of the job execution. If not specified, the statusDetails are unchanged. The maximum length of the value in the name/value pair is 1,024 characters.
    ///   - stepTimeoutInMinutes: Specifies the amount of time this device has to finish execution of this job. If the job execution status is not set to a terminal state before this timer expires, or before the timer is reset (by calling UpdateJobExecution, setting the status to IN_PROGRESS, and specifying a new timeout value in field stepTimeoutInMinutes) the job execution status will be automatically set to TIMED_OUT. Note that setting the step timeout has no effect on the in progress timeout that may have been specified when the job was created (CreateJob using field timeoutConfig). Valid values for this parameter range from 1 to 10080 (1 minute to 7 days).
    ///   - thingName: The name of the thing associated with the device.
    ///   - logger: Logger use during operation
    @inlinable
    public func startNextPendingJobExecution(
        statusDetails: [String: String]? = nil,
        stepTimeoutInMinutes: Int64? = nil,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> StartNextPendingJobExecutionResponse {
        let input = StartNextPendingJobExecutionRequest(
            statusDetails: statusDetails, 
            stepTimeoutInMinutes: stepTimeoutInMinutes, 
            thingName: thingName
        )
        return try await self.startNextPendingJobExecution(input, logger: logger)
    }

    /// Updates the status of a job execution. Requires permission to access the UpdateJobExecution action.
    @Sendable
    @inlinable
    public func updateJobExecution(_ input: UpdateJobExecutionRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> UpdateJobExecutionResponse {
        try await self.client.execute(
            operation: "UpdateJobExecution", 
            path: "/things/{thingName}/jobs/{jobId}", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Updates the status of a job execution. Requires permission to access the UpdateJobExecution action.
    ///
    /// Parameters:
    ///   - executionNumber: Optional. A number that identifies a particular job execution on a particular device.
    ///   - expectedVersion: Optional. The expected current version of the job execution. Each time you update the job execution, its version is incremented. If the version of the job execution stored in Jobs does not match, the update is rejected with a VersionMismatch error, and an ErrorResponse that contains the current job execution status data is returned. (This makes it unnecessary to perform a separate DescribeJobExecution request in order to obtain the job execution status data.)
    ///   - includeJobDocument: Optional. When set to true, the response contains the job document. The default is false.
    ///   - includeJobExecutionState: Optional. When included and set to true, the response contains the JobExecutionState data. The default is false.
    ///   - jobId: The unique identifier assigned to this job when it was created.
    ///   - status: The new status for the job execution (IN_PROGRESS, FAILED, SUCCESS, or REJECTED). This must be specified on every update.
    ///   - statusDetails:  Optional. A collection of name/value pairs that describe the status of the job execution. If not specified, the statusDetails are unchanged. The maximum length of the value in the name/value pair is 1,024 characters.
    ///   - stepTimeoutInMinutes: Specifies the amount of time this device has to finish execution of this job. If the job execution status is not set to a terminal state before this timer expires, or before the timer is reset (by again calling UpdateJobExecution, setting the status to IN_PROGRESS, and specifying a new timeout value in this field) the job execution status will be automatically set to TIMED_OUT. Note that setting or resetting the step timeout has no effect on the in progress timeout that may have been specified when the job was created (CreateJob using field timeoutConfig). Valid values for this parameter range from 1 to 10080 (1 minute to 7 days). A value of -1 is also valid and will cancel the current step timer (created by an earlier use of UpdateJobExecutionRequest).
    ///   - thingName: The name of the thing associated with the device.
    ///   - logger: Logger use during operation
    @inlinable
    public func updateJobExecution(
        executionNumber: Int64? = nil,
        expectedVersion: Int64? = nil,
        includeJobDocument: Bool? = nil,
        includeJobExecutionState: Bool? = nil,
        jobId: String,
        status: JobExecutionStatus,
        statusDetails: [String: String]? = nil,
        stepTimeoutInMinutes: Int64? = nil,
        thingName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> UpdateJobExecutionResponse {
        let input = UpdateJobExecutionRequest(
            executionNumber: executionNumber, 
            expectedVersion: expectedVersion, 
            includeJobDocument: includeJobDocument, 
            includeJobExecutionState: includeJobExecutionState, 
            jobId: jobId, 
            status: status, 
            statusDetails: statusDetails, 
            stepTimeoutInMinutes: stepTimeoutInMinutes, 
            thingName: thingName
        )
        return try await self.updateJobExecution(input, logger: logger)
    }
}

extension IoTJobsDataPlane {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: IoTJobsDataPlane, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}
